﻿using Common;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;

namespace Service
{
    public class ServiceFactory
    {
        private static Dictionary<string, object> Services = new Dictionary<string, object>();
        public static object CreateService(string name)
        {
            object service = null;
            if (Services.ContainsKey(name))
            {
                service = Services[name];
            }
            else
            {
                // 创建service
                service = Assembly.GetExecutingAssembly().CreateInstance($"Service.Impl.{name}Impl");
                var propInfo = service.GetType().GetProperty("CommandContext");
                propInfo.SetValue(service, CommonObject.CommandContext);
                Services.Add(name, service);
            }
            return service;
        }
    }
}
